package com.codegenerate.demo.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;
import java.time.LocalDateTime;


@TableName(value ="sys_template")
public class SysTemplate implements Serializable {
    @TableId(value = "id", type = IdType.AUTO)
    private long id;









    /**
     * 名称
     */
    @TableField(value = "name")
    private String name;




    /**
     * 模板内容
     */
    @TableField(value = "content")
    private  String content;




    /**
     * 分类id
     */
    @TableField(value = "class_id")
    private int classId;




    /**
     * 分类名称
     */
    @TableField(value = "class_name")
    private String className;


    // 后缀
    @TableField(value = "file_suffix")
    private String fileSuffix;


    public String getFileSuffix() {
        return fileSuffix;
    }

    public void setFileSuffix(String fileSuffix) {
        this.fileSuffix = fileSuffix;
    }

    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public  String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }

    public int getClassId() {
        return classId;
    }
    public void setClassId(int classId) {
        this.classId = classId;
    }

    public String getClassName() {
        return className;
    }
    public void setClassName(String className) {
        this.className = className;
    }






    /**
     * build
     */
    public static SysTemplate build(){
        SysTemplate tempEntity = new SysTemplate();
        return tempEntity;
    }

    /**
     * build
     */
    public  static void setDefaultValue(SysTemplate temp){

        if(temp.getId()<=0){
            temp.setId(0);
        }

        if(StringUtils.isEmpty(temp.getName())){
            temp.setName("");
        }



        if(temp.getClassId()<=0){
            temp.setClassId(0);
        }

        if(StringUtils.isEmpty(temp.getClassName())){
            temp.setClassName("");
        }





    }

    @JsonIgnore
    public LambdaQueryWrapper<SysTemplate> getQueryAll() {
        var  query = new QueryWrapper<SysTemplate>().lambda();

        if(this.id>0){
            query.eq(SysTemplate::getId, this.id);
        }

        if(!StringUtils.isEmpty(this.name)){
            query.eq(SysTemplate::getName, this.name);
        }



        if(this.classId>0){
            query.eq(SysTemplate::getClassId, this.classId);
        }

        if(!StringUtils.isEmpty(this.className)){
            query.eq(SysTemplate::getClassName, this.className);
        }

        if(!StringUtils.isEmpty(this.fileSuffix)){
            query.eq(SysTemplate::getFileSuffix, this.fileSuffix);
        }



        return  query;

    }

    @JsonIgnore
    public static LambdaQueryWrapper<SysTemplate> getQuery(){
        var query = new QueryWrapper<SysTemplate>().lambda();
        return query;
    }


    @JsonIgnore
    public LambdaUpdateWrapper<SysTemplate> getUpdateWrapper() {
        var  updateWrapper = new UpdateWrapper<SysTemplate>().lambda();

        if(this.id>0){

            updateWrapper.eq(SysTemplate::getId, this.id);

        }

        if(!StringUtils.isEmpty(this.name)){

            updateWrapper.set(SysTemplate::getName, this.name);

        }

        if(!StringUtils.isEmpty(this.content)){

            updateWrapper.set(SysTemplate::getContent, this.content);

        }

        if(this.classId>0){

            updateWrapper.set(SysTemplate::getClassId, this.classId);

        }

        if(!StringUtils.isEmpty(this.className)){

            updateWrapper.set(SysTemplate::getClassName, this.className);

        }


        if(!StringUtils.isEmpty(this.fileSuffix)){
            updateWrapper.set(SysTemplate::getFileSuffix, this.fileSuffix);
        }



        return updateWrapper;
    }

}

